﻿
namespace EventBusNet6.Controllers
{
    [ApiController]
    [Route("api")]
    public class FFmpegController : ControllerBase
    {
        private readonly Serilog.ILogger _logger = Log.Logger;
        private readonly IVideoCommandService _videoCommandService;
        public FFmpegController(IVideoCommandService videoCommandService)
        {
            _videoCommandService = videoCommandService;
        }
        /// <summary>
        /// 视频封面图
        /// </summary>
        /// <returns></returns>
        [HttpPost("videopicture")]
        public ApiResult CaptureVideoPicture(VideoPictureInput input )
        {
            VideoPictureOutput output = new VideoPictureOutput();
            var guid = Guid.NewGuid().ToString();
            output.Guid= guid;
            //_videoCommandService.CaptureVideoPicture(@"D:\convert\test.mp4", @"D:\convert\" + guid, 600, 400, guid);
            output.CatalogFile = _videoCommandService.CaptureVideoPicture(input.VideoPath, input.Width.Value, input.Height.Value, guid);
            return FormatterResult.Success(output);
        }
        /// <summary>
        /// 获取视频信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("videoinfo")]
        public ApiResult VideoInfo(VideoInfoInput input)
        {
            //if (string.IsNullOrEmpty(input.VideoPath)) return FormatterResult.Failed("路径参数不正确", 1);
            //var inputPath = @"D:\convert\test.mp4";
            StringBuilder videojson = new StringBuilder();
            string guid =Guid.NewGuid().ToString();
            var output = _videoCommandService.VideoInfo(input.VideoPath, guid);
            return FormatterResult.Success(output);
        }

        /// <summary>
        /// 获取音频信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("audioinfo")]
        public ApiResult AudioInfo(AudioInfoInput input )
        {
            if (string.IsNullOrEmpty(input.AudioPath)) return FormatterResult.Failed("路径参数不正确", 1);
            //var inputPath = @"D:\convert\土豆.mp3";
            string guid = Guid.NewGuid().ToString();
            var output = _videoCommandService.AudioInfo(input.AudioPath, guid);
            return FormatterResult.Success(output);
        }
    }
}
